#pragma once

#include <iostream>

#include "Protocol.hpp"

class Calculator
{
public:
    Calculator()
    {
    }

    Response Excute(const Request &req)
    {
        Response res;
        LOG(LogLevel::DEBUG)<<"********req.(Oper): "<<req.Oper();
        switch (req.Oper())
        {
        case '+':
            res.SetResult(req.X() + req.Y());
            break;
        case '-':
            res.SetResult(req.X() - req.Y());
            break;
        case '*':
            res.SetResult(req.X() * req.Y());
            break;
        case '/':
        {
            if (req.Y())
                res.SetResult(req.X() / req.Y());
            else
                res.SetCode(1); // code == 1表示除0的非法操作
        }
        break;
        case '%':
            if (req.Y())
                res.SetResult(req.X() % req.Y());
            else
                res.SetCode(2); // code == 2表示模0的非法操作
            break;
        default:
            res.SetCode(3); //code == 3 表示非法的计算操作
            break;
        }
        return res;
    }
    ~Calculator()
    {
    }
};